package com.vainycos.lotterysearch.schedule;

import com.vainycos.lotterysearch.enums.LotteryEnum;
import com.vainycos.lotterysearch.exception.BusinessException;
import com.vainycos.lotterysearch.model.LuckyLottery;
import com.vainycos.lotterysearch.service.BigLotteryService;
import com.vainycos.lotterysearch.service.DoubleColorService;
import com.vainycos.lotterysearch.service.LuckyLotteryService;
import com.vainycos.lotterysearch.service.notify.DingNotify;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

/**
 * @author: Vainycos
 * @description 福彩定时同步数据
 * @date: 2022/11/10 11:03
 */
@Slf4j
@Service
public class LotterySyncData {

    @Autowired
    private BigLotteryService bigLotteryService;

    @Autowired
    private DoubleColorService doubleColorService;

    @Autowired
    private LuckyLotteryService luckyLotteryService;

    @Autowired
    private DingNotify dingNotify;

    /**
     * 超级大乐透晚上9-10点，每15分钟同步一次
     */
    @Scheduled(cron = "0 0/15 21-22 * * *")
    public void syncBigLotteryBall(){
        try {
            bigLotteryService.syncInsert();
        }catch (BusinessException e){
            log.error("{}", e.getMessage());
        }
    }

    /**
     * 双色球 晚上9-10点，每15分钟同步一次
     */
    @Scheduled(cron = "0 0/15 21-22 * * *")
    public void syncDoubleColorBall(){
        try {
            doubleColorService.syncInsert();
        }catch (BusinessException e){
            log.error("{}", e.getMessage());
        }
    }

    /**
     * 排列三
     */
    @Scheduled(cron = "0 0/15 21-22 * * *")
    public void pl3(){
        LuckyLottery luckyLottery = luckyLotteryService.insertNextLotteryByType(LotteryEnum.PL3);
        if(luckyLottery != null){
            dingNotify.notifyLuckyLottery(luckyLottery);
        }
    }

    /**
     * 排列五
     */
    @Scheduled(cron = "0 0/15 21-22 * * *")
    public void pl5(){
        LuckyLottery luckyLottery = luckyLotteryService.insertNextLotteryByType(LotteryEnum.PL5);
        if(luckyLottery != null){
            dingNotify.notifyLuckyLottery(luckyLottery);
        }
    }
}
